<%@page import="docs.BufferedHttpResponseWrapper"%>
<%@page import="libaray.PutCache"%>
<%@page import="java.util.ArrayList"%>
<%@page import="gson.Question"%>
<%
	String url = request.getRequestURI();
	if(request.getQueryString()!=null)
	{
		url += "?" + request.getQueryString();
	} 
	Document doc=null;
	try{
		doc = Jsoup.parse(new URL("http://stackoverflow.com"+url.replace("/stack", "")), 30000);
	} catch (Exception e){
		out.print("error");
		return;
	}
	String des = doc.select(".post-text").html().replaceAll("\\<.*?\\>", "");
	if(des.length() > 200)
	{
		des = des.substring(0,200)+" ...";
	}
	Elements elements1 = doc.select(".post-taglist .post-tag");
	String key = "";
	ArrayList<String> list = new ArrayList<String>();
	for(int i=0;i<elements1.size();i++)
	{
		key += elements1.get(i).text()+",";
		list.add(elements1.get(i).text());
	}
	key = key.replaceAll(",$","");
	Question question = new Question();
	question.setTitle(doc.select("#question-header .question-hyperlink").text());
	question.setLink(url);
	question.setBody(des);
	question.setTags(list);
	PutCache.putCacheDomain(question,"update");
	
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="org.jsoup.select.Elements"%>
<%@page import="org.jsoup.nodes.Element"%>
<%@page import="java.net.URL"%>
<%@page import="org.jsoup.Jsoup"%>
<%@page import="org.jsoup.nodes.Document"%>
<html xmlns="http://www.w3.org/1999/xhtml"  dir="ltr">
	<head>
		<title><%=doc.select("#question-header .question-hyperlink").text() %> - garden question</title>
		<meta name="description" content="<%=des%>"/>
		<meta name="Keywords" content="<%=key%>"/>	
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta id="metaLanguage" http-equiv="Content-Language" content="en" />
		<link rel='stylesheet' type='text/css' href='/css/faq.css' />
	</head>
	<body>
		<div class="tl">
			
		</div>
		<div class="hd">
			<a href="/" class="lg"><img src="/images/logwo.jpg" alt="logo"/></a>
			<div class="advh">
				<script type="text/javascript">
google_ad_client = "ca-pub-1271973886625217";
/* garden 468 */
google_ad_slot = "5677374104";
google_ad_width = 468;
google_ad_height = 60;

</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
			</div>
			<div class="clear"></div>
		</div>
		
		<div class="bd">
			<div class="bl">
				<form action="/search.html" id="cse-main-search-box">
					<input type="hidden" name="cx"
						value="014427715721718913619:taaptwrkwpk" /> <input type="hidden"
						name="cof" value="FORID:10" /> <input type="hidden" name="ie"
						value="UTF-8" /> <input id="cse-main-search-text" type="text"
						name="q" autocomplete="on" class="input_search" style="width:450px;"/> <input type="submit" name="sa"
						value="Search" />
				</form><br/><br/>
			
				<script type="text/javascript">
google_ad_client = "ca-pub-1271973886625217";
/* garden 728 */
google_ad_slot = "0724466085";
google_ad_width = 728;
google_ad_height = 90;

</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
				<h1><%=doc.select("#question-header .question-hyperlink").text() %></h1>
				<div class="clear"></div>
				<div class="adt">
					<!-- AddThis Button BEGIN -->
					<div class="addthis_toolbox addthis_default_style addthis_32x32_style">
					<a class="addthis_button_preferred_1"></a>
					<a class="addthis_button_preferred_2"></a>
					<a class="addthis_button_preferred_3"></a>
					<a class="addthis_button_preferred_4"></a>
					<a class="addthis_button_compact"></a>
					<a class="addthis_counter addthis_bubble_style"></a>
					</div>
					<script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script>
					<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4d6f3cdb1d190d60"></script>
					<!-- AddThis Button END -->
				</div>
				<div class="adt so">
					<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
					<g:plusone size="standard" count="true"></g:plusone>
				</div>
				<div class="clear"></div>
				<br/>
				
				<strong>Question By : </strong> <a href="<%=doc.select("#question .user-details a").attr("href") %>" class="author"><%=doc.select("#question .user-details a").text() %></a>
				<br/>
				<%=doc.select(".post-text").html() %>
				<div class="clear"></div>
				<%
					Elements elements = doc.select(".post-taglist");
					elements.select("img").remove();
					out.print(elements.html().replace("post-tag","tags"));
				%>
				<hr size="1"/>
				<h2>Answer</h2>
				<div class="clear"></div>
				<br/>
				<%
					Elements elements2 = doc.select(".answercell");
					if(elements2.size()>0)
					{
						for(int i=0;i<elements2.size();i++)
						{
				%>
							<strong>Answer By : </strong> <a href="<%=elements2.get(i).select(".user-details a").attr("href") %>" class="author"><%=elements2.get(i).select(".user-details a").text() %></a>
							<br/><br/>
							<%=elements2.get(i).select(".post-text").html()%><br/>	
				<%
						}
					}
				%>
			</div>
			<div class="br">
				<script type="text/javascript">
google_ad_client = "ca-pub-1271973886625217";
/* garden 160 */
google_ad_slot = "7748382713";
google_ad_width = 160;
google_ad_height = 600;

</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
				<ul class="vr">
					<%
					Elements elements3 = doc.select(".sidebar-related .spacer");
					if(elements3.size()>0)
					{
						for(int i=0;i<elements3.size();i++)
						{
					%>
							<li><%=elements3.get(i).html() %></li>
					<%
						}
					}
					%>
				</ul>
			</div>
			<div class="clear"></div>
		</div>
		
		
		<div class="ft">
			Question Network @ 2012 All rights reserved.
			<a href="/privacy-policy.jsp">Privacy policy</a>
			<br/><br/>
           	
			<img src="http://code.google.com/appengine/images/appengine-silver-120x30.gif" alt="Powered by Google App Engine" />
		</div>
	</body>
</html>	